import { configureStore } from '@reduxjs/toolkit'
import type { TypedUseSelectorHook } from 'react-redux'
import { useSelector } from 'react-redux'

import { capacityManageSlice } from './toolkitSlice/capacityManageSlice'
import { loginAuthTokenSlice } from './toolkitSlice/loginAuthTokenSlice'
import { loginEntSlice } from './toolkitSlice/loginEntSlice'
import { loginRoleSlice } from './toolkitSlice/loginRoleSlice'
import { loginTokenSlice } from './toolkitSlice/loginTokenSlice'
import { loginUserSlice } from './toolkitSlice/loginUserSlice'
import { serviceUserIdSlice } from './toolkitSlice/serviseUserIdSlice'

export const store = configureStore({
  reducer: {
    loginUser: loginUserSlice.reducer,
    loginEnt: loginEntSlice.reducer,
    loginToken: loginTokenSlice.reducer,
    loginAuthToken: loginAuthTokenSlice.reducer,
    loginRole: loginRoleSlice.reducer,
    serviceUserId: serviceUserIdSlice.reducer,
    capacityManageStore: capacityManageSlice.reducer
  },
  middleware: (getDefaultMiddleware) =>
    getDefaultMiddleware({ serializableCheck: false })
})

export type RootState = ReturnType<typeof store.getState>
export type AppDispatch = typeof store.dispatch

export const useAppSelector: TypedUseSelectorHook<RootState> = useSelector
